import 'package:edu/constants/app_images.dart';
import 'package:edu/constants/app_strings.dart';
import 'package:flutter/material.dart';

class EmptyContentWidget extends StatelessWidget {
  final bool isLoading; // 加载中
  final bool isError; // 错误
  final Function? reloadAction; // 重新加载操作
  final String? buttonTitle; // 按钮标题
  final Function? otherAction; // 其他操作
  const EmptyContentWidget({
    super.key,
    required this.isLoading,
    required this.isError,
    this.reloadAction,
    this.buttonTitle,
    this.otherAction,
  });

  @override
  Widget build(BuildContext context) {
    String imagePath;
    if (isLoading) {
      imagePath = AppImages.loading;
    } else if (isError) {
      imagePath = AppImages.loadingFailed;
    } else {
      imagePath = AppImages.noContent;
    }
    return Center(
      child: Column(
        children: [
          const Spacer(),
          Stack(
            children: [
              Image.asset(imagePath, fit: BoxFit.cover),
              if (isLoading == false && isError == true)
                Positioned(
                  bottom: 0,
                  left: 0,
                  right: 0,
                  child: ElevatedButton(
                    onPressed: () {
                      if (reloadAction != null) {
                        reloadAction!();
                      }
                    },
                    child: const Text(AppStrings.reload),
                  ),
                ),
              if (isLoading == false && isError == false && buttonTitle != null)
                Positioned(
                  bottom: 0,
                  left: 0,
                  right: 0,
                  child: ElevatedButton(
                    onPressed: () {
                      if (otherAction != null) {
                        otherAction!();
                      }
                    },
                    child: Text(buttonTitle!),
                  ),
                ),
            ],
          ),
          const Spacer(),
        ],
      ),
    );
  }
}
